<template>
  <div v-loading="loading">
    <div class="add_btn_top">
      <el-button size="mini" @click="back">返 回</el-button>
      <!-- <el-button
        type="primary"
        size="mini"
        icon="el-icon-printer"
        v-print="printObj"
        >打 印</el-button
      > -->
      <el-button size="mini" @click="handleEdit" icon="el-icon-edit-outline"
        >编 辑</el-button
      >
      <el-button
        type="danger"
        size="mini"
        icon="el-icon-delete"
        @click="deleteBtn"
        >删 除</el-button
      >
      <!-- <el-button size="mini" @click="handleEmport"
        ><svg-icon
          class="svg-icon"
          icon-class="export"
          style="margin-right: 4px"
        />导 出</el-button
      > -->
    </div>
    <!-- <pdf id="printTab" :src="src" ref="pdf"></pdf> -->
    <!-- <Pdfpage :src="src" :name="details.name" ref="pdf"></Pdfpage> -->
    <iframe
      v-init-screen-h="10"
      style="width: 100%"
      :src="src"
      :key="iframeKey"
      frameborder="0"
    ></iframe>
    <!-- <AddDialog
      :templateList="templateList"
      :token="token"
      :showDialog.sync="showDialog"
      :isedit="true"
      @closeDialog="closeDialog"
      ref="addDialogRef"
    ></AddDialog> -->
    <AddDialog
      :details="details.technology"
      :isTechnoNavto="false"
      :templateList="templateList"
      :token="token"
      :showDialog.sync="showDialog"
      :isedit="true"
      @closeDialog="closeDialog"
      ref="dialogRef"
    ></AddDialog>
  </div>
</template>

<script>
// import pdf from "vue-pdf-signature";
// import CMapReaderFactory from "vue-pdf-signature/src/CMapReaderFactory";
import {
  getTechnologyToken,
  delFormulass,
  getTemplate,
  getFormulaToken
} from "@/api/technology";
import { download } from "@/utils/download";
import AddDialog from "./AddDialog2.vue";
// import pdf from "vue-pdf-signature";
// import CMapReaderFactory from "vue-pdf-signature/src/CMapReaderFactory";
import { filtersFileUrl } from "@/filter/index";
import { generateId } from "@/utils/index";
export default {
  namr: "recipeExhibition",
  components: {
    // pdf,
    AddDialog
  },
  data() {
    return {
      printObj: {
        id: "printTest",
        popTitle: "",
        extraHead: ""
      },
      token: "",
      tabHtml: "",
      details: { url: "", name: "" },
      minioClient: null,
      src: "",
      numPages: 0,
      page: 1,
      currentPage: 0,
      showDialog: false,
      templateList: [],
      loading: false,
      type: 1,
      iframeKey: "1"
    };
  },
  mounted() {
    this.token = this.$route.query.token;
    this.type = this.$route.query.type;
    console.log("  this.type :>> ", this.type);
    this.init();
    this.getTemplateList();
  },
  methods: {
    back() {
      this.$router.replace({
        name: "recipeList"
      });
    },
    closeDialog(isRefresh, token) {
      // isRefresh是否刷新

      if (isRefresh) {
        this.init();
        // this.$router.replace({
        //   name: "recipeExhibition",
        //   query: {
        //     token,
        //   },
        // });
        // this.token = token;
        // this.$router.go(0);
        // this.$router.push({
        //   path: "/_empty",
        //   query: {
        //     data: JSON.stringify({ token: this.token }),
        //     path: "recipeExhibition",
        //   },
        // });
      }
      this.showDialog = false;
    },
    //获取模板列表
    getTemplateList() {
      return new Promise((resolve, reject) => {
        var params = {
          page: 1,
          pageSize: 0
        };
        getTemplate(params).then(res => {
          const { results } = res.data;
          this.templateList = results;
          resolve();
        });
      });
    },
    async init() {
      let res;
      // 2主工艺 1配方
      res = await getFormulaToken(this.token, false);
      const { data } = res;
      this.details = data;
      const token1 = `${this.details.partNumber}_${this.details.entrustProcessNumber}_${this.details.processNumber}_${this.details.version}`;
      this.src = `${process.env.VUE_APP_JIMU_URL}/jmreport/view/${data.reportId}?token2=${this.details.token}&token1=${token1}=&Authorization=Bearer ${this.$store.state.user.accessToken}`;
      this.iframeKey = generateId();
    },
    //删除
    deleteBtn() {
      var that = this;
      this.$confirm("是否确认删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(async () => {
        await delFormulass(this.token);
        this.$msg({
          type: "success",
          message: "删除成功!"
        });
        this.$router.push({
          name: "recipeList"
        });
      });
    },
    handleEdit() {
      this.showDialog = true;
    },
    handleEmport() {
      // download(this.details.url, this.details.name);
      download(this.details.url, this.details.name || this.details.token);
    }
  }
};
</script>

<style lang="scss" scoped></style>
